﻿#region codejockey.net Copyright Banner
/***************************************************************\
 * Copyright 2010 codejockey.net.                                *
 *                                                               *
 * This code is property of codejockey.net and cannot be used    *
 * without explicit permission given by a codejockey.net         *
 * Representative.  For details contact: source@codejockey.net   *
 \***************************************************************/
#endregion

using System;

using codejockey.Shared.Text.ReplacementTokens;

namespace codejockey.BingPaper.Utils.ReplacementTokens
{
  public class DayReplacementToken : FormatStringReplacmentTokenBase
  {

    #region Private Fields

    private const string TokenText = "$day$";
    private const string TokenName = "DayReplacementToken";
    private const string TokenDescription = "The DayReplacementToken provides for the current day.";

    #endregion

    #region Constructors

    public DayReplacementToken(string formatString)
    {
      FormatString = formatString;
    }

    #endregion

    #region Public Methods

    public override string GetToken()
    {
      return TokenText;
    }
    
    public override string GetDescription()
    {
      return TokenDescription;
    }
    
    public override string GetName()
    {
      return TokenName;
    }
    
    public override string Replace(string tokenizedString)
    {
      tokenizedString = base.Replace(tokenizedString);

      if (tokenizedString.Contains(Token))
      {
        string dayString = string.Format(FormatString, DateTime.Now.Day);
        tokenizedString = tokenizedString.Replace(Token, dayString);
        Processed = true;
      }
      
      return tokenizedString;
    }

    #endregion

  }
}
